package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.DoctorMapper;
import com.ayou.eggguard.farm.pojo.Doctor;
import com.ayou.eggguard.farm.service.DoctorService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public PageBean<Doctor> getDoctors(Integer pageNum, Integer pageSize, String doctorName) {
        PageBean<Doctor> pb=new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<Doctor> list=doctorMapper.getDoctors(doctorName);
        Page<Doctor> p= (Page<Doctor>) list;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public void add(Doctor doctor) {
        doctorMapper.add(doctor);
    }

    @Override
    public void update(Doctor doctor) {
        doctorMapper.update(doctor);
    }

    @Override
    public void delete(Integer id) {
        doctorMapper.delete(id);
    }
}
